package com.cbn.ibcp.jishiting.rms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.rms.bo.ResourceStreamBO;
import com.cbn.ibcp.jishiting.rms.domain.ResourceStream;
import com.cbn.ibcp.jishiting.rms.mapper.ResourceStreamMapper;
import com.cbn.ibcp.jishiting.rms.service.IResourceStreamService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
@RequiredArgsConstructor
public class ResourceStreamServiceImpl implements IResourceStreamService {


    private final ResourceStreamMapper resourceStreamMapper;

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public ResourceStream selectById(Long id) {
        if (Objects.isNull(id)) {
            return null;
        }
        return resourceStreamMapper.selectById(id);
    }

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public ResourceStream selectByResIdAndQuality(String tenantCode, Long resId, Integer quality) {
        if (resId == null || quality == null) {
            return null;
        }
        LambdaQueryWrapper<ResourceStream> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourceStream::getResId, resId);
        queryWrapper.eq(ResourceStream::getQuality, quality);
        return resourceStreamMapper.selectOne(queryWrapper);
    }

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public List<ResourceStreamBO> selectWithEpisodeList(ResourceStreamBO resourceStreamBO) {
        if (resourceStreamBO == null) {
            return null;
        }
        return resourceStreamMapper.selectWithEpisodeList(resourceStreamBO);
    }
}
